/**
 * LabelDaoImpl.java created by zhangzhidong 
 * at 下午8:12:52 2016年4月18日
 */
package dao.wechatlab.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import dao.BaseDao;
import dao.wechatlab.LabelDao;
import pojo.weichatlab.Label;

/**
 * @author zhangzhidong
 *
 */
@Repository
@SuppressWarnings("unchecked")
public class LabelDaoImpl extends BaseDao implements LabelDao {
	/**
	 * @Param
	 * @Author zhangzhidong
	 */
	public List<Label> selectAllLabels() {
		// TODO Auto-generated method stub
		DetachedCriteria dc = DetachedCriteria.forClass(Label.class);
		return  (List<Label>) this.getHibernateTemplate().findByCriteria(dc);
	}
	public void saveLabel(Label label){
		this.getHibernateTemplate().save(label);
	}
	/**
	 * @Param
	 * @Author zhangzhidong
	 */
	public List<Label> selectAllParentIds() {
		// TODO Auto-generated method stub
		DetachedCriteria dc = DetachedCriteria.forClass(Label.class);

		dc.add(Restrictions.eq("parentId", new Integer(0)));
		return (List<Label>) this.getHibernateTemplate().findByCriteria(dc);
	}
	public List<Label> selectChildLables(Integer id){
		DetachedCriteria dc = DetachedCriteria.forClass(Label.class);
		dc.add(Restrictions.eq("parentId", id));
		return (List<Label>) getHibernateTemplate().findByCriteria(dc);
		
	}
	public List<Label> selectAllChildLabels(){
		DetachedCriteria dc = DetachedCriteria.forClass(Label.class);
		//parentId不为0就是子类
		dc.add(Restrictions.not(Restrictions.eq("parentId", new Integer(0))));
		return (List<Label>) getHibernateTemplate().findByCriteria(dc);
		
	}
	public void addLabel(Label l){
		this.getHibernateTemplate().persist(l);
	}

}
